package com.emm.yixun.estate.service.impl;
import java.util.List;
import javax.jws.WebService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.emm.yixun.common.exception.ResponseCode;
import com.emm.yixun.common.page.Page;
import com.emm.yixun.common.response.Response;
import com.emm.yixun.common.response.ResponseList;
import com.emm.yixun.basic.service.ProjectPremisesIndustDataVersionService;
import com.emm.yixun.common.model.ProjectPremisesIndustDataVersion;
import com.emm.yixun.common.model.dto.ProjectPremisesIndustDataVersionDto;
import com.emm.yixun.estate.service.ProjectPremisesIndustDataVersionServiceFacade;

@Service("projectPremisesIndustDataVersionServiceFacade")
@WebService(name="com.emm.yixun.estate.service.ProjectPremisesIndustDataVersionServiceFacade")
public class ProjectPremisesIndustDataVersionServiceFacadeImpl implements ProjectPremisesIndustDataVersionServiceFacade{
	private  final Logger   logger = LoggerFactory.getLogger(this.getClass()); 
	
	@Autowired
	private ProjectPremisesIndustDataVersionService service;

	@Override
	public Response<ProjectPremisesIndustDataVersionDto> save(ProjectPremisesIndustDataVersionDto dto) {
		Response<ProjectPremisesIndustDataVersionDto> response=new Response<ProjectPremisesIndustDataVersionDto>();
		try {
			if(null==dto){
				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("保存"));
				return response;
			}
			ProjectPremisesIndustDataVersionDto mDto=service.create(dto);
			if(null==mDto){
				response.fail("80000", "保存数据错误");
				return response;
			}
			response.success(mDto);
		} catch (Exception e) {
			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("保存数据错误：{}",e);
		}
		return response;
	}

	@Override
	public Response<Integer> updateByPrimaryKey(ProjectPremisesIndustDataVersionDto dto,Boolean selective) {
		Response<Integer> response=new Response<Integer>();
		try {
			if(null==selective || null==dto || null==dto.getId()){
				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("更新"));
				return response;
			}
			
			if(selective){
				int count=service.update(dto);
				if(count>0){
					response.success(Integer.valueOf(count));
				}else{
					response.fail("90001", "更新数据失败");
				}
			}else{
				response.fail("90000", "暂未实现,修改参数selective=true即可");
			}
		} catch (Exception e) {
			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("更新数据错误：{}",e);
		}
		return response;
	}

	@Override
	public Response<Integer> deleteByPrimaryKey(Long id) {
		Response<Integer> response=new Response<Integer>();
		try {
			if(null==id){
				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("删除"));
				return response;
			}
			ProjectPremisesIndustDataVersionDto mDto=new ProjectPremisesIndustDataVersionDto();
			mDto.setId(id);
			int count=service.destroy(mDto);
			if(count>0){
				response.success(Integer.valueOf(count));
			}else{
				response.fail("90001", "删除数据失败");
			}
		} catch (Exception e) {
			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("删除数据错误：{}",e);
		}
		return response;
	}
	
    @Override
	public Response<ProjectPremisesIndustDataVersion> findById(Long id) {
		Response<ProjectPremisesIndustDataVersion> response=new Response<ProjectPremisesIndustDataVersion>();
		try {
			if(null==id){
				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("主键查询"));
				return response;
			}
			ProjectPremisesIndustDataVersion entity=service.selectById(id);
			if(null==entity){
				response.fail("90001", "主键查询数据失败");
			}else{
				response.success(entity);;
			}
		} catch (Exception e) {
			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("主键查询数据错误：{}",e);
		}
		return response;
	}

	@Override
	public ResponseList<ProjectPremisesIndustDataVersion> findByDto(ProjectPremisesIndustDataVersionDto dto) {
		ResponseList<ProjectPremisesIndustDataVersion> response=new ResponseList<ProjectPremisesIndustDataVersion>();
		try {
			if(null==dto){
				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("查询"));
				return response;
			}
			List<ProjectPremisesIndustDataVersion> list=service.selectListByDto(dto);
			if(null==list){
				response.fail(ResponseCode.NO_DATA_FOUND.getCode(), ResponseCode.NO_DATA_FOUND.formatMessage("查询"));
				return response;
			}
			response.success(list);
		} catch (Exception e) {
			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("查询数据错误：{}",e);
		}
		return response;
	}

	@Override
	public Page<ProjectPremisesIndustDataVersion> findPageByDto(ProjectPremisesIndustDataVersionDto dto, Integer begin,Integer row) {
		Page<ProjectPremisesIndustDataVersion> response=new Page<ProjectPremisesIndustDataVersion>();
		try {
			if(null==dto || null==begin || null==row){
				response.setSuccess(false);
				response.setErrorMsg("参数不合法");
				return response;
			}
			Page<ProjectPremisesIndustDataVersion> page = service.getPageModel(dto, begin, row);
			if(null==page.getRows()){
				response.setSuccess(false);
				response.setErrorMsg("分页数据不存在");
				return response;
			}
			response=page;
			response.setSuccess(true);
		} catch (Exception e) {
			response.setSuccess(false);
			response.setErrorMsg(ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("查询分页数据错误：{}",e);
		}
		return response;
	}

	@Override
	public void insertByBatch(List<ProjectPremisesIndustDataVersionDto> list) {
		service.insertByBatch(list);
	}

	@Override
	public void deleteByBatch(ProjectPremisesIndustDataVersionDto projectPremisesIndustDataVersionDto) {
		// TODO Auto-generated method stub
       service.destroy(projectPremisesIndustDataVersionDto);
	}

}
